package dao.reader.impl;

import dao.BaseDao;
import dao.reader.ReaderDao;
import entity.Borrow_books;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * ReaderDaoImpl
 *
 * @author lenovo
 * @since 2023/8/25
 */
public class ReaderDaoImpl extends BaseDao implements ReaderDao {
    /**
     * 登录
     * @param id 用户id、用户账号
     * @param password
     * @return
     */
    @Override
    public String login(int id, String password) {
        int row=0;
        if (id == 0){
            return "账号不能为空";
        }
        if (password.equals("")){
            return "密码不能为空";
        }
        String sql="select Count(*) as c from borrow_card where id=?  and  password = ?";
        Connection conn = getConnection();
        PreparedStatement ps=null;
        ResultSet rs=null;
        try {
            ps=conn.prepareStatement(sql);
            ps.setInt(1, id);
            ps.setString(2,password);
            rs=ps.executeQuery();
            while (rs.next()) {
                row=rs.getInt("c");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            closeAll(rs,ps,conn);
        }
        return row == 0 ? "登录失败" : String.valueOf(row);
    }
}
